﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using LibKetoan;
using doiso;

namespace Ketoan
{
	/// <summary>
	/// Summary description for frmDutoanns.
	/// </summary>
	public class frmDutoanns : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label9;
		private System.Windows.Forms.DataGrid dataGrid1;
		private System.Windows.Forms.Button butMoi;
		private System.Windows.Forms.Button butSua;
		private System.Windows.Forms.Button butLuu;
		private System.Windows.Forms.Button butBoqua;
		private System.Windows.Forms.Button butHuy;
		private System.Windows.Forms.Button butIn;
		private System.Windows.Forms.Button butKetthuc;
		private string s_mmyy,sql,format_sotien,table="a_dutoanns";
		private int i_userid,itable,lctug_dutoanns,chucnang_k;
		private long l_id,l_idold,l_idctct;
		private bool bKhoaso,bNew,bAdmin;
		private AccessData a;
		private Doisototext doiso=new Doisototext();
		private DataTable dtmtm=new DataTable();
		private DataTable dtct=new DataTable();
		private DataTable dttk=new DataTable();
		private DataRow r;
		private System.Windows.Forms.TextBox find;
		private System.Windows.Forms.CheckBox chkIn;
		private System.Windows.Forms.ToolTip toolTip1;
		private System.ComponentModel.IContainer components;
		private System.Windows.Forms.Label label43;
		private System.Windows.Forms.ComboBox hoatdong;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.ComboBox chuong;
		private System.Windows.Forms.Label label50;
		private System.Windows.Forms.ComboBox lk;
		private System.Windows.Forms.TextBox ttkno;
		private System.Windows.Forms.TextBox tkno;
		private System.Windows.Forms.Label label13;
		private System.Windows.Forms.Label label16;
		private System.Windows.Forms.TextBox mtmno;
		private System.Windows.Forms.Label label17;
		private System.Windows.Forms.ComboBox kmno;
		private string s_chuong,s_lk,s_ngay;
		private LibList.List listmtm;
		private LibList.List listtkno;
		private long ltkno,lmtmno,l_idct;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label11;
		private System.Windows.Forms.ComboBox kmno2;
		private System.Windows.Forms.ComboBox kmno4;
		private System.Windows.Forms.Label label15;
		private System.Windows.Forms.ComboBox kmno3;
		private System.Windows.Forms.Label label14;
		private System.Windows.Forms.Label label12;
		private MaskedTextBox.MaskedTextBox dgiao;
		private MaskedTextBox.MaskedTextBox bsung;
		private MaskedTextBox.MaskedTextBox cong;
		private MaskedTextBox.MaskedTextBox ntruoc;
		private System.Windows.Forms.ComboBox loaikp;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.TextBox soctg;
		private System.Windows.Forms.DateTimePicker ngayg;
		private System.Windows.Forms.TextBox stemp;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.NumericUpDown q;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.ComboBox nhmuc;
		private System.Windows.Forms.Label label3;

		public frmDutoanns(AccessData acc,string mmyy,string _ngay,string _chuong,string _lk,int userid,string title,bool admin)
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
			a=acc;i_userid=userid;s_mmyy=mmyy;
			s_chuong=_chuong;s_lk=_lk;s_ngay=_ngay;
			bAdmin=admin;this.Text=title;
			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            this.components = new System.ComponentModel.Container();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmDutoanns));
            this.label9 = new System.Windows.Forms.Label();
            this.hoatdong = new System.Windows.Forms.ComboBox();
            this.dataGrid1 = new System.Windows.Forms.DataGrid();
            this.butMoi = new System.Windows.Forms.Button();
            this.butSua = new System.Windows.Forms.Button();
            this.butLuu = new System.Windows.Forms.Button();
            this.butBoqua = new System.Windows.Forms.Button();
            this.butHuy = new System.Windows.Forms.Button();
            this.butIn = new System.Windows.Forms.Button();
            this.butKetthuc = new System.Windows.Forms.Button();
            this.find = new System.Windows.Forms.TextBox();
            this.chkIn = new System.Windows.Forms.CheckBox();
            this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
            this.dgiao = new MaskedTextBox.MaskedTextBox();
            this.bsung = new MaskedTextBox.MaskedTextBox();
            this.label43 = new System.Windows.Forms.Label();
            this.label6 = new System.Windows.Forms.Label();
            this.chuong = new System.Windows.Forms.ComboBox();
            this.label50 = new System.Windows.Forms.Label();
            this.lk = new System.Windows.Forms.ComboBox();
            this.ttkno = new System.Windows.Forms.TextBox();
            this.tkno = new System.Windows.Forms.TextBox();
            this.label13 = new System.Windows.Forms.Label();
            this.label16 = new System.Windows.Forms.Label();
            this.mtmno = new System.Windows.Forms.TextBox();
            this.label17 = new System.Windows.Forms.Label();
            this.kmno = new System.Windows.Forms.ComboBox();
            this.cong = new MaskedTextBox.MaskedTextBox();
            this.ntruoc = new MaskedTextBox.MaskedTextBox();
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.label3 = new System.Windows.Forms.Label();
            this.loaikp = new System.Windows.Forms.ComboBox();
            this.listmtm = new LibList.List();
            this.listtkno = new LibList.List();
            this.label11 = new System.Windows.Forms.Label();
            this.kmno2 = new System.Windows.Forms.ComboBox();
            this.kmno4 = new System.Windows.Forms.ComboBox();
            this.label15 = new System.Windows.Forms.Label();
            this.kmno3 = new System.Windows.Forms.ComboBox();
            this.label14 = new System.Windows.Forms.Label();
            this.label12 = new System.Windows.Forms.Label();
            this.label4 = new System.Windows.Forms.Label();
            this.label5 = new System.Windows.Forms.Label();
            this.soctg = new System.Windows.Forms.TextBox();
            this.ngayg = new System.Windows.Forms.DateTimePicker();
            this.stemp = new System.Windows.Forms.TextBox();
            this.label7 = new System.Windows.Forms.Label();
            this.q = new System.Windows.Forms.NumericUpDown();
            this.label8 = new System.Windows.Forms.Label();
            this.nhmuc = new System.Windows.Forms.ComboBox();
            ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.q)).BeginInit();
            this.SuspendLayout();
            // 
            // label9
            // 
            this.label9.Location = new System.Drawing.Point(424, 5);
            this.label9.Name = "label9";
            this.label9.Size = new System.Drawing.Size(64, 23);
            this.label9.TabIndex = 0;
            this.label9.Text = "Hoạt động :";
            this.label9.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // hoatdong
            // 
            this.hoatdong.BackColor = System.Drawing.SystemColors.HighlightText;
            this.hoatdong.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.hoatdong.Enabled = false;
            this.hoatdong.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.hoatdong.Location = new System.Drawing.Point(488, 5);
            this.hoatdong.Name = "hoatdong";
            this.hoatdong.Size = new System.Drawing.Size(233, 21);
            this.hoatdong.TabIndex = 4;
            this.hoatdong.SelectedIndexChanged += new System.EventHandler(this.hoatdong_SelectedIndexChanged);
            this.hoatdong.KeyDown += new System.Windows.Forms.KeyEventHandler(this.hoatdong_KeyDown);
            // 
            // dataGrid1
            // 
            this.dataGrid1.AlternatingBackColor = System.Drawing.Color.Lavender;
            this.dataGrid1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                        | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.dataGrid1.BackColor = System.Drawing.Color.WhiteSmoke;
            this.dataGrid1.BackgroundColor = System.Drawing.SystemColors.Control;
            this.dataGrid1.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.dataGrid1.CaptionBackColor = System.Drawing.SystemColors.Control;
            this.dataGrid1.CaptionFont = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.dataGrid1.CaptionForeColor = System.Drawing.Color.MidnightBlue;
            this.dataGrid1.DataMember = "";
            this.dataGrid1.FlatMode = true;
            this.dataGrid1.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.dataGrid1.ForeColor = System.Drawing.Color.MidnightBlue;
            this.dataGrid1.GridLineColor = System.Drawing.Color.Gainsboro;
            this.dataGrid1.GridLineStyle = System.Windows.Forms.DataGridLineStyle.None;
            this.dataGrid1.HeaderFont = new System.Drawing.Font("Tahoma", 8F, System.Drawing.FontStyle.Bold);
            this.dataGrid1.HeaderForeColor = System.Drawing.Color.WhiteSmoke;
            this.dataGrid1.LinkColor = System.Drawing.Color.Teal;
            this.dataGrid1.Location = new System.Drawing.Point(8, 32);
            this.dataGrid1.Name = "dataGrid1";
            this.dataGrid1.ParentRowsBackColor = System.Drawing.Color.Gainsboro;
            this.dataGrid1.ParentRowsForeColor = System.Drawing.Color.MidnightBlue;
            this.dataGrid1.ReadOnly = true;
            this.dataGrid1.RowHeaderWidth = 10;
            this.dataGrid1.SelectionBackColor = System.Drawing.Color.CadetBlue;
            this.dataGrid1.SelectionForeColor = System.Drawing.Color.WhiteSmoke;
            this.dataGrid1.Size = new System.Drawing.Size(971, 384);
            this.dataGrid1.TabIndex = 90;
            this.dataGrid1.CurrentCellChanged += new System.EventHandler(this.dataGrid1_CurrentCellChanged);
            // 
            // butMoi
            // 
            this.butMoi.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.butMoi.Image = ((System.Drawing.Image)(resources.GetObject("butMoi.Image")));
            this.butMoi.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butMoi.Location = new System.Drawing.Point(172, 491);
            this.butMoi.Name = "butMoi";
            this.butMoi.Size = new System.Drawing.Size(60, 25);
            this.butMoi.TabIndex = 21;
            this.butMoi.Text = "      &Mới";
            this.butMoi.Click += new System.EventHandler(this.butMoi_Click);
            // 
            // butSua
            // 
            this.butSua.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.butSua.Image = ((System.Drawing.Image)(resources.GetObject("butSua.Image")));
            this.butSua.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butSua.Location = new System.Drawing.Point(235, 491);
            this.butSua.Name = "butSua";
            this.butSua.Size = new System.Drawing.Size(60, 25);
            this.butSua.TabIndex = 22;
            this.butSua.Text = "     &Sửa";
            this.butSua.Click += new System.EventHandler(this.butSua_Click);
            // 
            // butLuu
            // 
            this.butLuu.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.butLuu.Enabled = false;
            this.butLuu.Image = ((System.Drawing.Image)(resources.GetObject("butLuu.Image")));
            this.butLuu.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butLuu.Location = new System.Drawing.Point(298, 491);
            this.butLuu.Name = "butLuu";
            this.butLuu.Size = new System.Drawing.Size(60, 25);
            this.butLuu.TabIndex = 19;
            this.butLuu.Text = "     &Lưu";
            this.butLuu.Click += new System.EventHandler(this.butLuu_Click);
            // 
            // butBoqua
            // 
            this.butBoqua.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.butBoqua.Enabled = false;
            this.butBoqua.Image = ((System.Drawing.Image)(resources.GetObject("butBoqua.Image")));
            this.butBoqua.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butBoqua.Location = new System.Drawing.Point(361, 491);
            this.butBoqua.Name = "butBoqua";
            this.butBoqua.Size = new System.Drawing.Size(60, 25);
            this.butBoqua.TabIndex = 20;
            this.butBoqua.Text = "&Bỏ qua";
            this.butBoqua.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.butBoqua.Click += new System.EventHandler(this.butBoqua_Click);
            // 
            // butHuy
            // 
            this.butHuy.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.butHuy.Image = ((System.Drawing.Image)(resources.GetObject("butHuy.Image")));
            this.butHuy.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butHuy.Location = new System.Drawing.Point(424, 491);
            this.butHuy.Name = "butHuy";
            this.butHuy.Size = new System.Drawing.Size(60, 25);
            this.butHuy.TabIndex = 23;
            this.butHuy.Text = "     &Hủy";
            this.butHuy.Click += new System.EventHandler(this.butHuy_Click);
            // 
            // butIn
            // 
            this.butIn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.butIn.Image = ((System.Drawing.Image)(resources.GetObject("butIn.Image")));
            this.butIn.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butIn.Location = new System.Drawing.Point(487, 491);
            this.butIn.Name = "butIn";
            this.butIn.Size = new System.Drawing.Size(60, 25);
            this.butIn.TabIndex = 24;
            this.butIn.Text = "      &In";
            this.butIn.Click += new System.EventHandler(this.butIn_Click);
            // 
            // butKetthuc
            // 
            this.butKetthuc.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.butKetthuc.Image = ((System.Drawing.Image)(resources.GetObject("butKetthuc.Image")));
            this.butKetthuc.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butKetthuc.Location = new System.Drawing.Point(550, 491);
            this.butKetthuc.Name = "butKetthuc";
            this.butKetthuc.Size = new System.Drawing.Size(70, 25);
            this.butKetthuc.TabIndex = 25;
            this.butKetthuc.Text = "&Kết thúc";
            this.butKetthuc.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.butKetthuc.Click += new System.EventHandler(this.butKetthuc_Click);
            // 
            // find
            // 
            this.find.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.find.BackColor = System.Drawing.SystemColors.HighlightText;
            this.find.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.find.ForeColor = System.Drawing.Color.Red;
            this.find.Location = new System.Drawing.Point(778, 28);
            this.find.Name = "find";
            this.find.Size = new System.Drawing.Size(201, 21);
            this.find.TabIndex = 89;
            this.find.Text = "Tìm kiếm";
            this.find.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
            this.find.TextChanged += new System.EventHandler(this.find_TextChanged);
            this.find.Enter += new System.EventHandler(this.find_Enter);
            // 
            // chkIn
            // 
            this.chkIn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.chkIn.Location = new System.Drawing.Point(851, 488);
            this.chkIn.Name = "chkIn";
            this.chkIn.Size = new System.Drawing.Size(112, 16);
            this.chkIn.TabIndex = 98;
            this.chkIn.Text = "Xem trước khi in";
            // 
            // dgiao
            // 
            this.dgiao.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.dgiao.BackColor = System.Drawing.SystemColors.HighlightText;
            this.dgiao.Enabled = false;
            this.dgiao.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.dgiao.Location = new System.Drawing.Point(64, 464);
            this.dgiao.Masked = MaskedTextBox.MaskedTextBox.Mask.Decimal;
            this.dgiao.Name = "dgiao";
            this.dgiao.Size = new System.Drawing.Size(120, 21);
            this.dgiao.TabIndex = 15;
            this.dgiao.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            this.dgiao.Validated += new System.EventHandler(this.dgiao_Validated);
            // 
            // bsung
            // 
            this.bsung.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.bsung.BackColor = System.Drawing.SystemColors.HighlightText;
            this.bsung.Enabled = false;
            this.bsung.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.bsung.Location = new System.Drawing.Point(495, 464);
            this.bsung.Masked = MaskedTextBox.MaskedTextBox.Mask.Decimal;
            this.bsung.Name = "bsung";
            this.bsung.Size = new System.Drawing.Size(128, 21);
            this.bsung.TabIndex = 17;
            this.bsung.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            this.bsung.Validated += new System.EventHandler(this.bsung_Validated);
            // 
            // label43
            // 
            this.label43.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.label43.Location = new System.Drawing.Point(438, 464);
            this.label43.Name = "label43";
            this.label43.Size = new System.Drawing.Size(56, 23);
            this.label43.TabIndex = 75;
            this.label43.Text = "Bổ sung :";
            this.label43.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label6
            // 
            this.label6.Location = new System.Drawing.Point(312, 5);
            this.label6.Name = "label6";
            this.label6.Size = new System.Drawing.Size(56, 23);
            this.label6.TabIndex = 13;
            this.label6.Text = "Chương :";
            this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // chuong
            // 
            this.chuong.BackColor = System.Drawing.SystemColors.HighlightText;
            this.chuong.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.chuong.Enabled = false;
            this.chuong.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.chuong.Location = new System.Drawing.Point(368, 5);
            this.chuong.Name = "chuong";
            this.chuong.Size = new System.Drawing.Size(56, 21);
            this.chuong.TabIndex = 3;
            this.chuong.KeyDown += new System.Windows.Forms.KeyEventHandler(this.hoatdong_KeyDown);
            // 
            // label50
            // 
            this.label50.Location = new System.Drawing.Point(-24, 27);
            this.label50.Name = "label50";
            this.label50.Size = new System.Drawing.Size(72, 23);
            this.label50.TabIndex = 49;
            this.label50.Text = "LKhoản :";
            this.label50.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // lk
            // 
            this.lk.BackColor = System.Drawing.SystemColors.HighlightText;
            this.lk.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.lk.Enabled = false;
            this.lk.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lk.Location = new System.Drawing.Point(48, 28);
            this.lk.Name = "lk";
            this.lk.Size = new System.Drawing.Size(376, 21);
            this.lk.TabIndex = 6;
            this.lk.KeyDown += new System.Windows.Forms.KeyEventHandler(this.hoatdong_KeyDown);
            // 
            // ttkno
            // 
            this.ttkno.BackColor = System.Drawing.SystemColors.HighlightText;
            this.ttkno.Enabled = false;
            this.ttkno.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.ttkno.Location = new System.Drawing.Point(559, 28);
            this.ttkno.Name = "ttkno";
            this.ttkno.Size = new System.Drawing.Size(213, 21);
            this.ttkno.TabIndex = 8;
            // 
            // tkno
            // 
            this.tkno.BackColor = System.Drawing.SystemColors.HighlightText;
            this.tkno.Enabled = false;
            this.tkno.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.tkno.Location = new System.Drawing.Point(488, 28);
            this.tkno.Name = "tkno";
            this.tkno.Size = new System.Drawing.Size(70, 21);
            this.tkno.TabIndex = 7;
            this.tkno.TextChanged += new System.EventHandler(this.tkno_TextChanged);
            this.tkno.Validated += new System.EventHandler(this.tkno_Validated);
            this.tkno.KeyDown += new System.Windows.Forms.KeyEventHandler(this.tkno_KeyDown);
            // 
            // label13
            // 
            this.label13.Location = new System.Drawing.Point(408, 27);
            this.label13.Name = "label13";
            this.label13.Size = new System.Drawing.Size(80, 23);
            this.label13.TabIndex = 51;
            this.label13.Text = "Số TK :";
            this.label13.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label16
            // 
            this.label16.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.label16.Location = new System.Drawing.Point(358, 435);
            this.label16.Name = "label16";
            this.label16.Size = new System.Drawing.Size(56, 23);
            this.label16.TabIndex = 54;
            this.label16.Text = "Mục/TM :";
            this.label16.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // mtmno
            // 
            this.mtmno.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.mtmno.BackColor = System.Drawing.SystemColors.HighlightText;
            this.mtmno.Enabled = false;
            this.mtmno.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.mtmno.Location = new System.Drawing.Point(411, 437);
            this.mtmno.Name = "mtmno";
            this.mtmno.Size = new System.Drawing.Size(569, 21);
            this.mtmno.TabIndex = 10;
            this.mtmno.TextChanged += new System.EventHandler(this.mtmno_TextChanged);
            this.mtmno.KeyDown += new System.Windows.Forms.KeyEventHandler(this.mtmno_KeyDown);
            // 
            // label17
            // 
            this.label17.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.label17.Enabled = false;
            this.label17.Location = new System.Drawing.Point(956, 530);
            this.label17.Name = "label17";
            this.label17.Size = new System.Drawing.Size(10, 23);
            this.label17.TabIndex = 56;
            this.label17.Text = "K mục 1 :";
            this.label17.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.label17.Visible = false;
            // 
            // kmno
            // 
            this.kmno.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.kmno.BackColor = System.Drawing.SystemColors.HighlightText;
            this.kmno.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.kmno.Enabled = false;
            this.kmno.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.kmno.Location = new System.Drawing.Point(940, 532);
            this.kmno.Name = "kmno";
            this.kmno.Size = new System.Drawing.Size(10, 21);
            this.kmno.TabIndex = 11;
            this.kmno.Visible = false;
            this.kmno.KeyDown += new System.Windows.Forms.KeyEventHandler(this.hoatdong_KeyDown);
            // 
            // cong
            // 
            this.cong.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.cong.BackColor = System.Drawing.SystemColors.HighlightText;
            this.cong.Enabled = false;
            this.cong.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.cong.Location = new System.Drawing.Point(678, 464);
            this.cong.Masked = MaskedTextBox.MaskedTextBox.Mask.Decimal;
            this.cong.Name = "cong";
            this.cong.Size = new System.Drawing.Size(301, 21);
            this.cong.TabIndex = 18;
            this.cong.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            // 
            // ntruoc
            // 
            this.ntruoc.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.ntruoc.BackColor = System.Drawing.SystemColors.HighlightText;
            this.ntruoc.Enabled = false;
            this.ntruoc.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.ntruoc.Location = new System.Drawing.Point(284, 464);
            this.ntruoc.Masked = MaskedTextBox.MaskedTextBox.Mask.Decimal;
            this.ntruoc.Name = "ntruoc";
            this.ntruoc.Size = new System.Drawing.Size(160, 21);
            this.ntruoc.TabIndex = 16;
            this.ntruoc.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            this.ntruoc.Validated += new System.EventHandler(this.ntruoc_Validated);
            // 
            // label1
            // 
            this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.label1.Location = new System.Drawing.Point(614, 464);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(56, 23);
            this.label1.TabIndex = 108;
            this.label1.Text = "Cộng :";
            this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label2
            // 
            this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.label2.Location = new System.Drawing.Point(180, 464);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(104, 23);
            this.label2.TabIndex = 110;
            this.label2.Text = "Năm trước chuyển :";
            this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label3
            // 
            this.label3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.label3.Location = new System.Drawing.Point(-17, 464);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(80, 23);
            this.label3.TabIndex = 109;
            this.label3.Text = "Được giao :";
            this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // loaikp
            // 
            this.loaikp.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.loaikp.BackColor = System.Drawing.SystemColors.HighlightText;
            this.loaikp.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.loaikp.Enabled = false;
            this.loaikp.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.loaikp.Location = new System.Drawing.Point(778, 5);
            this.loaikp.Name = "loaikp";
            this.loaikp.Size = new System.Drawing.Size(201, 21);
            this.loaikp.TabIndex = 5;
            this.loaikp.KeyDown += new System.Windows.Forms.KeyEventHandler(this.hoatdong_KeyDown);
            // 
            // listmtm
            // 
            this.listmtm.BackColor = System.Drawing.SystemColors.Info;
            this.listmtm.ColumnCount = 0;
            this.listmtm.Location = new System.Drawing.Point(664, 536);
            this.listmtm.MatchBufferTimeOut = 1000;
            this.listmtm.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
            this.listmtm.Name = "listmtm";
            this.listmtm.Size = new System.Drawing.Size(75, 17);
            this.listmtm.TabIndex = 101;
            this.listmtm.TextIndex = -1;
            this.listmtm.TextMember = null;
            this.listmtm.ValueIndex = -1;
            this.listmtm.Visible = false;
            // 
            // listtkno
            // 
            this.listtkno.BackColor = System.Drawing.SystemColors.Info;
            this.listtkno.ColumnCount = 0;
            this.listtkno.Location = new System.Drawing.Point(232, 544);
            this.listtkno.MatchBufferTimeOut = 1000;
            this.listtkno.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
            this.listtkno.Name = "listtkno";
            this.listtkno.Size = new System.Drawing.Size(75, 17);
            this.listtkno.TabIndex = 104;
            this.listtkno.TextIndex = -1;
            this.listtkno.TextMember = null;
            this.listtkno.ValueIndex = -1;
            this.listtkno.Visible = false;
            this.listtkno.KeyDown += new System.Windows.Forms.KeyEventHandler(this.listtkno_KeyDown);
            // 
            // label11
            // 
            this.label11.Location = new System.Drawing.Point(711, 5);
            this.label11.Name = "label11";
            this.label11.Size = new System.Drawing.Size(56, 23);
            this.label11.TabIndex = 129;
            this.label11.Text = "Nguồn :";
            this.label11.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // kmno2
            // 
            this.kmno2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.kmno2.BackColor = System.Drawing.SystemColors.HighlightText;
            this.kmno2.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.kmno2.Enabled = false;
            this.kmno2.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.kmno2.Location = new System.Drawing.Point(745, 532);
            this.kmno2.Name = "kmno2";
            this.kmno2.Size = new System.Drawing.Size(10, 21);
            this.kmno2.TabIndex = 12;
            this.kmno2.Visible = false;
            this.kmno2.KeyDown += new System.Windows.Forms.KeyEventHandler(this.hoatdong_KeyDown);
            // 
            // kmno4
            // 
            this.kmno4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.kmno4.BackColor = System.Drawing.SystemColors.HighlightText;
            this.kmno4.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.kmno4.Enabled = false;
            this.kmno4.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.kmno4.Location = new System.Drawing.Point(940, 532);
            this.kmno4.Name = "kmno4";
            this.kmno4.Size = new System.Drawing.Size(10, 21);
            this.kmno4.TabIndex = 14;
            this.kmno4.Visible = false;
            this.kmno4.KeyDown += new System.Windows.Forms.KeyEventHandler(this.hoatdong_KeyDown);
            // 
            // label15
            // 
            this.label15.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.label15.Enabled = false;
            this.label15.Location = new System.Drawing.Point(953, 530);
            this.label15.Name = "label15";
            this.label15.Size = new System.Drawing.Size(10, 23);
            this.label15.TabIndex = 138;
            this.label15.Text = "K mục 4 :";
            this.label15.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.label15.Visible = false;
            // 
            // kmno3
            // 
            this.kmno3.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.kmno3.BackColor = System.Drawing.SystemColors.HighlightText;
            this.kmno3.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.kmno3.Enabled = false;
            this.kmno3.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.kmno3.Location = new System.Drawing.Point(745, 532);
            this.kmno3.Name = "kmno3";
            this.kmno3.Size = new System.Drawing.Size(205, 21);
            this.kmno3.TabIndex = 13;
            this.kmno3.Visible = false;
            this.kmno3.KeyDown += new System.Windows.Forms.KeyEventHandler(this.hoatdong_KeyDown);
            // 
            // label14
            // 
            this.label14.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.label14.Enabled = false;
            this.label14.Location = new System.Drawing.Point(758, 532);
            this.label14.Name = "label14";
            this.label14.Size = new System.Drawing.Size(10, 23);
            this.label14.TabIndex = 137;
            this.label14.Text = "K mục 3 :";
            this.label14.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.label14.Visible = false;
            // 
            // label12
            // 
            this.label12.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.label12.Enabled = false;
            this.label12.Location = new System.Drawing.Point(758, 530);
            this.label12.Name = "label12";
            this.label12.Size = new System.Drawing.Size(10, 23);
            this.label12.TabIndex = 136;
            this.label12.Text = "K mục 2 :";
            this.label12.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.label12.Visible = false;
            // 
            // label4
            // 
            this.label4.Location = new System.Drawing.Point(56, 5);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(72, 23);
            this.label4.TabIndex = 139;
            this.label4.Text = "Q. định :";
            this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label5
            // 
            this.label5.Location = new System.Drawing.Point(184, 5);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(56, 23);
            this.label5.TabIndex = 140;
            this.label5.Text = "Ngày :";
            this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // soctg
            // 
            this.soctg.BackColor = System.Drawing.SystemColors.HighlightText;
            this.soctg.Enabled = false;
            this.soctg.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.soctg.Location = new System.Drawing.Point(128, 5);
            this.soctg.Name = "soctg";
            this.soctg.Size = new System.Drawing.Size(80, 21);
            this.soctg.TabIndex = 1;
            this.soctg.KeyDown += new System.Windows.Forms.KeyEventHandler(this.hoatdong_KeyDown);
            // 
            // ngayg
            // 
            this.ngayg.CustomFormat = "dd/MM/yyyy";
            this.ngayg.Enabled = false;
            this.ngayg.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.ngayg.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
            this.ngayg.Location = new System.Drawing.Point(240, 5);
            this.ngayg.Name = "ngayg";
            this.ngayg.Size = new System.Drawing.Size(80, 21);
            this.ngayg.TabIndex = 2;
            this.ngayg.KeyDown += new System.Windows.Forms.KeyEventHandler(this.hoatdong_KeyDown);
            // 
            // stemp
            // 
            this.stemp.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.stemp.BackColor = System.Drawing.SystemColors.HighlightText;
            this.stemp.Enabled = false;
            this.stemp.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.stemp.Location = new System.Drawing.Point(336, 276);
            this.stemp.Name = "stemp";
            this.stemp.Size = new System.Drawing.Size(315, 21);
            this.stemp.TabIndex = 141;
            // 
            // label7
            // 
            this.label7.Location = new System.Drawing.Point(8, 5);
            this.label7.Name = "label7";
            this.label7.Size = new System.Drawing.Size(40, 23);
            this.label7.TabIndex = 142;
            this.label7.Text = "Quí :";
            this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // q
            // 
            this.q.BackColor = System.Drawing.SystemColors.HighlightText;
            this.q.Enabled = false;
            this.q.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.q.Location = new System.Drawing.Point(48, 5);
            this.q.Maximum = new decimal(new int[] {
            4,
            0,
            0,
            0});
            this.q.Minimum = new decimal(new int[] {
            1,
            0,
            0,
            0});
            this.q.Name = "q";
            this.q.Size = new System.Drawing.Size(32, 21);
            this.q.TabIndex = 0;
            this.q.Value = new decimal(new int[] {
            1,
            0,
            0,
            0});
            this.q.KeyDown += new System.Windows.Forms.KeyEventHandler(this.hoatdong_KeyDown);
            // 
            // label8
            // 
            this.label8.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.label8.Location = new System.Drawing.Point(-9, 435);
            this.label8.Name = "label8";
            this.label8.Size = new System.Drawing.Size(72, 23);
            this.label8.TabIndex = 143;
            this.label8.Text = "Nhóm mục :";
            this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // nhmuc
            // 
            this.nhmuc.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.nhmuc.BackColor = System.Drawing.SystemColors.HighlightText;
            this.nhmuc.Enabled = false;
            this.nhmuc.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.nhmuc.Location = new System.Drawing.Point(64, 437);
            this.nhmuc.Name = "nhmuc";
            this.nhmuc.Size = new System.Drawing.Size(288, 21);
            this.nhmuc.TabIndex = 9;
            this.nhmuc.KeyDown += new System.Windows.Forms.KeyEventHandler(this.nhmuc_KeyDown);
            // 
            // frmDutoanns
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(987, 573);
            this.Controls.Add(this.nhmuc);
            this.Controls.Add(this.label8);
            this.Controls.Add(this.q);
            this.Controls.Add(this.label7);
            this.Controls.Add(this.kmno3);
            this.Controls.Add(this.kmno);
            this.Controls.Add(this.lk);
            this.Controls.Add(this.hoatdong);
            this.Controls.Add(this.ngayg);
            this.Controls.Add(this.soctg);
            this.Controls.Add(this.label5);
            this.Controls.Add(this.label4);
            this.Controls.Add(this.dgiao);
            this.Controls.Add(this.kmno2);
            this.Controls.Add(this.kmno4);
            this.Controls.Add(this.label15);
            this.Controls.Add(this.label14);
            this.Controls.Add(this.label12);
            this.Controls.Add(this.loaikp);
            this.Controls.Add(this.label11);
            this.Controls.Add(this.bsung);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.ntruoc);
            this.Controls.Add(this.cong);
            this.Controls.Add(this.ttkno);
            this.Controls.Add(this.mtmno);
            this.Controls.Add(this.label17);
            this.Controls.Add(this.label16);
            this.Controls.Add(this.tkno);
            this.Controls.Add(this.label13);
            this.Controls.Add(this.label50);
            this.Controls.Add(this.chuong);
            this.Controls.Add(this.label6);
            this.Controls.Add(this.label43);
            this.Controls.Add(this.chkIn);
            this.Controls.Add(this.find);
            this.Controls.Add(this.butKetthuc);
            this.Controls.Add(this.butIn);
            this.Controls.Add(this.butHuy);
            this.Controls.Add(this.butBoqua);
            this.Controls.Add(this.butLuu);
            this.Controls.Add(this.butSua);
            this.Controls.Add(this.butMoi);
            this.Controls.Add(this.label9);
            this.Controls.Add(this.dataGrid1);
            this.Controls.Add(this.listmtm);
            this.Controls.Add(this.listtkno);
            this.Controls.Add(this.stemp);
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.Name = "frmDutoanns";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Dự toán ngân sách được giao";
            this.Load += new System.EventHandler(this.frmDutoanns_Load);
            ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.q)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

		}
		#endregion

		private void frmDutoanns_Load(object sender, System.EventArgs e)
		{			
			chkIn.Checked=a.bPreview;lctug_dutoanns=a.lctug_dutoanns;
			int mm=int.Parse(s_mmyy.Substring(0,2));chucnang_k=LibKetoan.AccessData.chucnang_k;
			q.Value=(mm<4)?1:(mm<7)?2:(mm<10)?3:4;
			format_sotien=a.format_sotien(0);
			bKhoaso=a.bKhoaso(s_mmyy);

			loaikp.DisplayMember="TEN";
			loaikp.ValueMember="ID";

			hoatdong.DisplayMember="TEN";
			hoatdong.ValueMember="ID";
			hoatdong.DataSource=a.get_data("select * from a_hoatdong where sudung=1 order by stt").Tables[0];
			load_loaikp();

			sql="select * from a_dmchuong where sudung=1";
			if (s_chuong!="") sql+=" and id in ("+s_chuong.Substring(0,s_chuong.Length-1)+")";
			sql+=" order by stt";
			chuong.DisplayMember="TEN";
			chuong.ValueMember="ID";
			chuong.DataSource=a.get_data(sql).Tables[0];
        
			lk.DisplayMember="LK";
			lk.ValueMember="ID";
			lk.DataSource=a.get_data("select id,lk||' '||tlk as lk,tlk from a_dmlk order by stt").Tables[0];

			kmno.DisplayMember="TEN";
			kmno.ValueMember="ID";

			kmno2.DisplayMember="TEN";
			kmno2.ValueMember="ID";

			kmno3.DisplayMember="TEN";
			kmno3.ValueMember="ID";

			kmno4.DisplayMember="TEN";
			kmno4.ValueMember="ID";

			nhmuc.ValueMember="ID";
			nhmuc.DisplayMember="TENNHOM";
			nhmuc.DataSource=a.get_data("select * from a_dmnhom").Tables[0];

			dttk=a.get_data("select stk,ttk,congno,tinhchat,mlns,ctmlns,loaikm,loaikm2,loaikm3,loaikm4,id from a_dmtk where sudung=1 and c=1 and substr(stk,1,3) in ('008','009') order by stk").Tables[0];
			dtmtm=a.get_data("select * from a_dmch where sudung=1 order by stk").Tables[0];

			listtkno.DisplayMember="STK";
			listtkno.ValueMember="TTK";
			listtkno.DataSource=dttk;

			listmtm.DisplayMember="STK";
			listmtm.ValueMember="TTK";

			load_grid();
			AddGridTableStyle();
			ref_text(0);
		}

		private void load_grid()
		{
			dataGrid1.DataSource=null;
			
			sql="select a.id,a.chuong,a.lk,a.stk,a.khoanmuc,a.khoanmuc2,a.khoanmuc3,a.khoanmuc4,a.muc,a.loaikp,a.kp,a.hoatdong,a.q,a.nhmuc,";
			sql+="a.soctg,to_char(a.ngayg,'dd/mm/yyyy') as ngayg,a.dgiao,a.ntruoc,a.bsung,";
			sql+="a.dgiao+a.ntruoc+a.bsung as cong,e.stk as stkmuc,f.tennhom as tenmuc,c.lk as tenlk,d.stk as sotk,d.ttk,g.ma,g.ma||' '||nvl(g.ten,' ') as tenkhoanmuc,a.idct";
			sql+=" from "+table+s_mmyy.Substring(2)+" a inner join a_dmchuong b on a.chuong=b.id ";
			sql+=" inner join a_dmlk c on a.lk=c.id ";
			sql+=" inner join a_dmtk d on a.stk=d.id ";
			sql+=" left join a_dmch e on a.muc=e.id ";
			sql+=" left join a_dmnhom f on a.nhmuc=f.id ";
			sql+=" left join a_dmkhoanmuc g on a.khoanmuc=g.id ";
			sql+=" left join a_hoatdong h on a.hoatdong=h.id ";
			//sql+=" where a.thanggs='"+s_mmyy.Substring(0,2)+"'";
            //if (s_chuong!="") sql+=" and a.chuong in ("+s_chuong.Substring(0,s_chuong.Length-1)+")";
            //if (s_lk!="") sql+=" and a.lk in ("+s_lk.Substring(0,s_lk.Length-1)+")";
            //if (!bAdmin) sql+=" and a.userid="+i_userid;
			sql+=" order by a.soctg,a.ngayg";
			dtct=a.get_data(sql).Tables[0];
			dataGrid1.DataSource=dtct;
			tongcong();

		}

		private void ref_text(long id)
		{
			try
			{
				int i=dataGrid1.CurrentCell.RowNumber;
				l_id=(id==0)?long.Parse(dataGrid1[i,0].ToString()):l_id;
				r=a.getrowbyid(dtct,"id="+l_id);
				if (r!=null)
				{
					soctg.Text=r["soctg"].ToString();
					string ng=r["ngayg"].ToString();
					ngayg.Value=new DateTime(int.Parse(ng.Substring(6,4)),int.Parse(ng.Substring(3,2)),int.Parse(ng.Substring(0,2)),0,0,0);
					chuong.SelectedValue=r["chuong"].ToString();
					hoatdong.SelectedValue=r["hoatdong"].ToString();
					load_loaikp();
					loaikp.SelectedValue=r["kp"].ToString();
					lk.SelectedValue=int.Parse(r["lk"].ToString());
					ltkno=long.Parse(r["stk"].ToString());
					lmtmno=long.Parse(r["muc"].ToString());
					decimal st=decimal.Parse(r["dgiao"].ToString());
					dgiao.Text=st.ToString(format_sotien);
					st=decimal.Parse(r["ntruoc"].ToString());
					ntruoc.Text=st.ToString(format_sotien);
					st=decimal.Parse(r["bsung"].ToString());
					bsung.Text=st.ToString(format_sotien);
					st=decimal.Parse(r["dgiao"].ToString())+decimal.Parse(r["ntruoc"].ToString())+decimal.Parse(r["bsung"].ToString());
					cong.Text=st.ToString(format_sotien);

					DataRow r1=a.getrowbyid(dttk,"id="+ltkno);
					mtmno.Text="";
					if (r1!=null)
					{
						tkno.Text=r1["stk"].ToString();
						ttkno.Text=r1["ttk"].ToString();
					}
					load_mtm(tkno.Text,mtmno,kmno);
					if (lmtmno!=0)
					{
						r1=a.getrowbyid(dtmtm,"id="+lmtmno);
						if (r1!=null)
							mtmno.Text=r1["stk"].ToString();
					}
					kmno.SelectedIndex=kmno2.SelectedIndex=kmno3.SelectedIndex=kmno4.SelectedIndex=-1;
					kmno.SelectedValue=r["khoanmuc"].ToString();
					kmno2.SelectedValue=r["khoanmuc2"].ToString();
					kmno3.SelectedValue=r["khoanmuc3"].ToString();
					kmno4.SelectedValue=r["khoanmuc4"].ToString();
					q.Value=decimal.Parse(r["q"].ToString());
					nhmuc.SelectedValue=r["nhmuc"].ToString();
					l_idct=long.Parse(r["idct"].ToString());
				}
			}
			catch{emp_detail();}
		}

		public Color MyGetColorRowCol(int row, int col)
		{
			//if (this.dataGrid1[row,15].ToString()=="0") return Color.Red;
			//else 
			return Color.Black;
		}

		public delegate Color delegateGetColorRowCol(int row, int col);
		public class DataGridColoredTextBoxColumn : DataGridTextBoxColumn
		{
			private delegateGetColorRowCol _getColorRowCol;
			private int _column;
			public DataGridColoredTextBoxColumn(delegateGetColorRowCol getcolorRowCol, int column)
			{
				_getColorRowCol = getcolorRowCol;
				_column = column;
			}
			protected override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager source, int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush foreBrush, bool alignToRight)
			{
				try
				{
					foreBrush = new SolidBrush(_getColorRowCol(rowNum, this._column));
					//backBrush = new SolidBrush(Color.GhostWhite);
				}
				catch{}
				finally
				{
					base.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight);
				}
			}
		}

		private void AddGridTableStyle()
		{
			DataGridColoredTextBoxColumn TextCol;
			delegateGetColorRowCol de = new delegateGetColorRowCol(MyGetColorRowCol);
			DataGridTableStyle ts =new DataGridTableStyle();
			ts.MappingName = dtct.TableName;
			ts.AlternatingBackColor = Color.Beige;
			ts.BackColor = Color.GhostWhite;
			ts.ForeColor = Color.MidnightBlue;
			ts.GridLineColor = Color.RoyalBlue;
			ts.HeaderBackColor = Color.MidnightBlue;
			ts.HeaderForeColor = Color.Lavender;
			ts.SelectionBackColor = Color.Teal;
			ts.SelectionForeColor = Color.PaleGreen;
			ts.ReadOnly=false;
			ts.RowHeaderWidth=10;
			
			TextCol=new DataGridColoredTextBoxColumn(de, 0);
			TextCol.MappingName = "id";
			TextCol.HeaderText = "";
			TextCol.Width = 0;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridColoredTextBoxColumn(de, 1);
			TextCol.MappingName = "soctg";
			TextCol.HeaderText = "Quyết định";
			TextCol.Width = 100;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridColoredTextBoxColumn(de, 2);
			TextCol.MappingName = "ngayg";
			TextCol.HeaderText = "Ngày";
			TextCol.Width = 70;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridColoredTextBoxColumn(de, 3);
			TextCol.MappingName = "sotk";
			TextCol.HeaderText = "Số tài khoản";
			TextCol.Width = 70;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridColoredTextBoxColumn(de, 4);
			TextCol.MappingName = "tenmuc";
			TextCol.HeaderText = "Nhóm mục";
			TextCol.Width = dataGrid1.Width-(30+100+70+70+150+100+100+100+100);
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridColoredTextBoxColumn(de,5);
			TextCol.MappingName = "stkmuc";
			TextCol.HeaderText = "Mục/tiểu mục";
			TextCol.Width = 150;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridColoredTextBoxColumn(de,6);
			TextCol.MappingName = "dgiao";
			TextCol.HeaderText = "Được giao";
			TextCol.Width = 100;
			TextCol.Format=format_sotien;
			TextCol.Alignment=HorizontalAlignment.Right;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridColoredTextBoxColumn(de,7);
			TextCol.MappingName = "ntruoc";
			TextCol.HeaderText = "Năm trước chuyển";
			TextCol.Width = 100;
			TextCol.Format=format_sotien;
			TextCol.Alignment=HorizontalAlignment.Right;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridColoredTextBoxColumn(de,8);
			TextCol.MappingName = "bsung";
			TextCol.HeaderText = "Bổ sung";
			TextCol.Width = 100;
			TextCol.Format=format_sotien;
			TextCol.Alignment=HorizontalAlignment.Right;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridColoredTextBoxColumn(de,9);
			TextCol.MappingName = "cong";
			TextCol.HeaderText = "Tổng cộng";
			TextCol.Width = 100;
			TextCol.Format=format_sotien;
			TextCol.Alignment=HorizontalAlignment.Right;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);
		}


		private void butKetthuc_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void ena_object(bool ena)
		{
			find.Enabled=!ena;
			nhmuc.Enabled=q.Enabled=soctg.Enabled=ngayg.Enabled=hoatdong.Enabled=chuong.Enabled=loaikp.Enabled=ena;
			lk.Enabled=tkno.Enabled=ena;
			dataGrid1.Enabled=!ena;
			dgiao.Enabled=ntruoc.Enabled=bsung.Enabled=ena;
			butLuu.Enabled=butBoqua.Enabled=ena;
			butMoi.Enabled=butSua.Enabled=butHuy.Enabled=butIn.Enabled=butKetthuc.Enabled=!ena;
		}

		private void emp_detail()
		{
			l_idct=l_id=0;
			//ngayg.Value=new DateTime(int.Parse(s_ngay.Substring(6,4)),int.Parse(s_ngay.Substring(3,2)),int.Parse(s_ngay.Substring(0,2)),0,0,0);
			kmno2.Text=kmno3.Text=kmno4.Text=tkno.Text=ttkno.Text=mtmno.Text=kmno.Text="";
			cong.Text=dgiao.Text=ntruoc.Text=bsung.Text="";
			kmno2.SelectedIndex=kmno3.SelectedIndex=kmno4.SelectedIndex=kmno.SelectedIndex=-1;
			mtmno.Enabled=kmno.Enabled=false;
		}

		private void butMoi_Click(object sender, System.EventArgs e)
		{
			if (bKhoaso)
			{
				MessageBox.Show("Số liệu tháng "+s_mmyy.Substring(0,2)+" năm "+s_mmyy.Substring(2,2)+" đã khóa !\nNếu cần thay đổi thì vào mục khai báo hệ thống",a.Msg);
				return;
			}
			ena_object(true);
			emp_detail();
			bNew=true;
			q.Focus();
		}

		private void butSua_Click(object sender, System.EventArgs e)
		{
			if (dtct.Rows.Count==0) return;
			if (bKhoaso)
			{
				MessageBox.Show("Số liệu tháng "+s_mmyy.Substring(0,2)+" năm "+s_mmyy.Substring(2,2)+" đã khóa !\nNếu cần thay đổi thì vào mục khai báo hệ thống",a.Msg);
				return;
			}
			ena_object(true);
			l_idold=l_id;
			bNew=false;
			int km=kmno.SelectedIndex;
			int km2=kmno2.SelectedIndex;
			int km3=kmno3.SelectedIndex;
			int km4=kmno4.SelectedIndex;
			load_mtm(tkno.Text,mtmno,kmno);
			kmno.SelectedIndex=km;
			kmno2.SelectedIndex=km2;
			kmno3.SelectedIndex=km3;
			kmno4.SelectedIndex=km4;
			listmtm.Hide();
			soctg.Focus();
		}

		private bool Kiemtra()
		{
			ltkno=lmtmno=0;
			if (tkno.Text=="")
			{
				MessageBox.Show("Nhập số tài khoản !",a.Msg);
				tkno.Focus();
				return false;
			}
			r=a.getrowbyid(dttk,"stk='"+tkno.Text+"'");
			if (r==null)
			{
				MessageBox.Show("Tài khoản không hợp lệ !",a.Msg);
				tkno.Focus();
				return false;
			}
			ltkno=long.Parse(r["id"].ToString());
			if (mtmno.Text!="")
			{
				r=a.getrowbyid(dtmtm,"stk='"+mtmno.Text+"'");
				if (r==null)
				{
					MessageBox.Show("Mục tiểu mục không hợp lệ !",a.Msg);
					mtmno.Focus();
					return false;
				}
				lmtmno=long.Parse(r["id"].ToString());
			}
			decimal st=(cong.Text!="")?decimal.Parse(cong.Text):0;
			if (st==0)
			{
				MessageBox.Show("Nhập số tiền !",a.Msg);
				dgiao.Focus();
				return false;
			}
			return true;
		}

		private void butLuu_Click(object sender, System.EventArgs e)
		{
			if (!Kiemtra()) return;
			l_id=(bNew)?a.getIddutoanns():l_id;
			l_idct=(bNew)?a.getIdct():l_idct;
			DataTable dt=new DataTable();
			itable = a.tableid("",table+s_mmyy.Substring(2));
			if (bNew) a.upd_eve_tables(itable, i_userid, "ins");
			else
			{
				dt=a.get_data("select a.*,b.thangqt from a_dutoanns"+s_mmyy.Substring(2)+" a,a_ctct"+s_mmyy.Substring(2)+" b where a.idct=b.idct(+) and a.id="+l_id).Tables[0];
				a.upd_eve_tables(itable, i_userid, "upd");
				a.upd_eve_upd_del(itable, i_userid, "upd",a.fields(table+s_mmyy.Substring(2),"id="+l_id));
			}
			if (!a.updDutoanns(s_mmyy,l_id,int.Parse(chuong.SelectedValue.ToString()),lmtmno,(nhmuc.SelectedIndex!=-1 && nhmuc.Enabled)?int.Parse(nhmuc.SelectedValue.ToString()):0,int.Parse(lk.SelectedValue.ToString()),ltkno,(kmno.SelectedIndex!=-1)?long.Parse(kmno.SelectedValue.ToString()):0,(kmno2.SelectedIndex!=-1)?long.Parse(kmno2.SelectedValue.ToString()):0,(kmno3.SelectedIndex!=-1)?long.Parse(kmno3.SelectedValue.ToString()):0,(kmno4.SelectedIndex!=-1)?long.Parse(kmno4.SelectedValue.ToString()):0,int.Parse(hoatdong.SelectedValue.ToString()),q.Value,"",(loaikp.SelectedIndex!=-1)?int.Parse(loaikp.SelectedValue.ToString()):0,soctg.Text,ngayg.Text,0,(dgiao.Text!="")?decimal.Parse(dgiao.Text):0,(ntruoc.Text!="")?decimal.Parse(ntruoc.Text):0,(bsung.Text!="")?decimal.Parse(bsung.Text):0,i_userid,l_idct))
			{
				MessageBox.Show("Không cập nhật được thông tin dự toán ngân sách !",a.Msg);
				return;
			}
			decimal zstien=((dgiao.Text!="")?decimal.Parse(dgiao.Text):0)+((ntruoc.Text!="")?decimal.Parse(ntruoc.Text):0)+((bsung.Text!="")?decimal.Parse(bsung.Text):0);
			a.updCt(s_mmyy,l_idct,0,"",int.Parse(chuong.SelectedValue.ToString()),chucnang_k,int.Parse(hoatdong.SelectedValue.ToString()),lctug_dutoanns,soctg.Text,ngayg.Text,ngayg.Text,"Dự toán ngân sách được giao",ltkno,0,0,0,zstien,0,s_mmyy.Substring(0,2),0,0,0,0,"",0,i_userid);
			if (!bNew)
			{
				foreach(DataRow r1 in dt.Rows)
				{
					a.updSodu("a_sd",a.delete,s_mmyy,
						0,long.Parse(r1["chuong"].ToString()),0,
						long.Parse(r1["lk"].ToString()),0,0,long.Parse(r1["stk"].ToString()),0,
						long.Parse(r1["khoanmuc"].ToString()),0,long.Parse(r1["khoanmuc2"].ToString()),0,
						long.Parse(r1["khoanmuc3"].ToString()),0,long.Parse(r1["khoanmuc4"].ToString()),0,
						long.Parse(r1["muc"].ToString()),0,long.Parse(r1["hoatdong"].ToString()),
						decimal.Parse(r1["dgiao"].ToString())+decimal.Parse(r1["ntruoc"].ToString())+decimal.Parse(r1["bsung"].ToString()));
					if (r1["thangqt"].ToString()!="")
					{
						a.updSodu("a_sdc",a.delete,r1["thangqt"].ToString()+s_mmyy.Substring(2),
							0,long.Parse(r1["chuong"].ToString()),0,
							long.Parse(r1["lk"].ToString()),0,0,long.Parse(r1["stk"].ToString()),0,
							long.Parse(r1["khoanmuc"].ToString()),0,long.Parse(r1["khoanmuc2"].ToString()),0,
							long.Parse(r1["khoanmuc3"].ToString()),0,long.Parse(r1["khoanmuc4"].ToString()),0,
							long.Parse(r1["muc"].ToString()),0,long.Parse(r1["hoatdong"].ToString()),
							decimal.Parse(r1["dgiao"].ToString())+decimal.Parse(r1["ntruoc"].ToString())+decimal.Parse(r1["bsung"].ToString()));
					}
				}
			}
			dt=a.get_data("select a.*,b.thangqt,b.id as idctct from a_dutoanns"+s_mmyy.Substring(2)+" a,a_ctct"+s_mmyy.Substring(2)+" b where a.idct=b.idct(+) and a.id="+l_id).Tables[0];
			foreach(DataRow r1 in dt.Rows)
			{
				if(bNew) l_idctct=a.getIdctct();
				else l_idctct=long.Parse(r1["idctct"].ToString());
				a.updCtct(s_mmyy,l_idctct,l_idct,1,int.Parse(r1["lk"].ToString()),
					"Dự toán ngân sách được giao",long.Parse(r1["stk"].ToString()),0,
					long.Parse(r1["khoanmuc"].ToString()),0,long.Parse(r1["khoanmuc2"].ToString()),0,
					long.Parse(r1["khoanmuc3"].ToString()),0,long.Parse(r1["khoanmuc4"].ToString()),0,
					long.Parse(r1["muc"].ToString()),0,
					decimal.Parse(r1["dgiao"].ToString())+decimal.Parse(r1["ntruoc"].ToString())+decimal.Parse(r1["bsung"].ToString()),0,
					0,1,1,0,0,lctug_dutoanns,
					soctg.Text,ngayg.Text,int.Parse(r1["chuong"].ToString()),0,0,0,int.Parse(r1["hoatdong"].ToString()),i_userid);

//				a.updCtct(s_mmyy,a.getIdctct(),l_idct,1,int.Parse(r1["lk"].ToString()),
//					"Dự toán ngân sách được giao",long.Parse(r1["stk"].ToString()),0,
//					long.Parse(r1["khoanmuc"].ToString()),0,long.Parse(r1["khoanmuc2"].ToString()),0,
//					long.Parse(r1["khoanmuc3"].ToString()),0,long.Parse(r1["khoanmuc4"].ToString()),0,
//					long.Parse(r1["muc"].ToString()),0,
//					decimal.Parse(r1["dgiao"].ToString())+decimal.Parse(r1["ntruoc"].ToString())+decimal.Parse(r1["bsung"].ToString()),0,
//					0,1,1,0,0,lctug_dutoanns,
//					soctg.Text,ngayg.Text,int.Parse(r1["chuong"].ToString()),0,0,0,int.Parse(r1["hoatdong"].ToString()),i_userid);

				a.updSodu("a_sd",a.insert,s_mmyy,0,long.Parse(r1["chuong"].ToString()),0,
					long.Parse(r1["lk"].ToString()),0,0,long.Parse(r1["stk"].ToString()),0,
					long.Parse(r1["khoanmuc"].ToString()),0,long.Parse(r1["khoanmuc2"].ToString()),0,
					long.Parse(r1["khoanmuc3"].ToString()),0,long.Parse(r1["khoanmuc4"].ToString()),0,
					long.Parse(r1["muc"].ToString()),0,long.Parse(r1["hoatdong"].ToString()),
					decimal.Parse(r1["dgiao"].ToString())+decimal.Parse(r1["ntruoc"].ToString())+decimal.Parse(r1["bsung"].ToString()));
	
				if (r1["thangqt"].ToString()!="")
				{
					a.updSodu("a_sdc",a.insert,r1["thangqt"].ToString()+s_mmyy.Substring(2),
						0,long.Parse(r1["chuong"].ToString()),0,
						long.Parse(r1["lk"].ToString()),0,0,long.Parse(r1["stk"].ToString()),0,
						long.Parse(r1["khoanmuc"].ToString()),0,long.Parse(r1["khoanmuc2"].ToString()),0,
						long.Parse(r1["khoanmuc3"].ToString()),0,long.Parse(r1["khoanmuc4"].ToString()),0,
						long.Parse(r1["muc"].ToString()),0,long.Parse(r1["hoatdong"].ToString()),
						decimal.Parse(r1["dgiao"].ToString())+decimal.Parse(r1["ntruoc"].ToString())+decimal.Parse(r1["bsung"].ToString()));
				}				
			}
			a.updDtsd("",s_mmyy,i_userid);
			if (a.get_data("select * from a_mmyy where mmyy='"+s_mmyy+"'").Tables[0].Rows.Count==0) a.updMmyy(s_mmyy,i_userid);
			load_grid();
			ref_text(0);
			ena_object(false);
			nhmuc.Enabled=listmtm.Enabled=kmno2.Enabled=kmno3.Enabled=kmno4.Enabled=kmno.Enabled=false;
			listmtm.Hide();
			butMoi.Focus();
		}

		private void butBoqua_Click(object sender, System.EventArgs e)
		{
			l_id=l_idold;
			ref_text(l_id);
			ena_object(false);
			listmtm.Hide();
			nhmuc.Enabled=listmtm.Enabled=kmno2.Enabled=kmno3.Enabled=kmno4.Enabled=kmno.Enabled=false;
			butMoi.Focus();
		}

		private void dataGrid1_CurrentCellChanged(object sender, System.EventArgs e)
		{
			ref_text(0);
		}

		private void butHuy_Click(object sender, System.EventArgs e)
		{
			try
			{
				if (dtct.Rows.Count==0) return;
				if (bKhoaso)
				{
					MessageBox.Show("Số liệu tháng "+s_mmyy.Substring(0,2)+" năm "+s_mmyy.Substring(2,2)+" đã khóa !\nNếu cần thay đổi thì vào mục khai báo hệ thống",a.Msg);
					return;
				}
				if (MessageBox.Show("Đồng ý hủy số phiếu này ?",a.Msg,MessageBoxButtons.YesNo,MessageBoxIcon.Question)==DialogResult.Yes)
				{
					a.updDtsd("",s_mmyy,i_userid);
					itable = a.tableid("", table+s_mmyy.Substring(2));
					a.upd_eve_tables(itable, i_userid, "del");
					a.upd_eve_upd_del(itable, i_userid, "del", a.fields(table+s_mmyy.Substring(2), "id=" + l_id));
					DataTable dt=a.get_data("select a.*,b.thangqt from a_dutoanns"+s_mmyy.Substring(2)+" a,a_ctct"+s_mmyy.Substring(2)+" b where a.idct=b.idct and a.id="+l_id).Tables[0];
					foreach(DataRow r1 in dt.Rows)
					{
						a.updSodu("a_sd",a.delete,s_mmyy,
							0,long.Parse(r1["chuong"].ToString()),0,
							long.Parse(r1["lk"].ToString()),0,0,long.Parse(r1["stk"].ToString()),0,
							long.Parse(r1["khoanmuc"].ToString()),0,long.Parse(r1["khoanmuc2"].ToString()),0,
							long.Parse(r1["khoanmuc3"].ToString()),0,long.Parse(r1["khoanmuc4"].ToString()),0,
							long.Parse(r1["muc"].ToString()),0,long.Parse(r1["hoatdong"].ToString()),
							decimal.Parse(r1["dgiao"].ToString())+decimal.Parse(r1["ntruoc"].ToString())+decimal.Parse(r1["bsung"].ToString()));
						if (r1["thangqt"].ToString()!="")
						{
							a.updSodu("a_sdc",a.delete,r1["thangqt"].ToString()+s_mmyy.Substring(2),
								0,long.Parse(r1["chuong"].ToString()),0,
								long.Parse(r1["lk"].ToString()),0,0,long.Parse(r1["stk"].ToString()),0,
								long.Parse(r1["khoanmuc"].ToString()),0,long.Parse(r1["khoanmuc2"].ToString()),0,
								long.Parse(r1["khoanmuc3"].ToString()),0,long.Parse(r1["khoanmuc4"].ToString()),0,
								long.Parse(r1["muc"].ToString()),0,long.Parse(r1["hoatdong"].ToString()),
								decimal.Parse(r1["dgiao"].ToString())+decimal.Parse(r1["ntruoc"].ToString())+decimal.Parse(r1["bsung"].ToString()));
						}
					}
					a.execute_data("delete from a_ctct"+s_mmyy.Substring(2)+" where idct="+l_idct);
					a.execute_data("delete from a_ct"+s_mmyy.Substring(2)+" where id="+l_idct);
					a.execute_data("delete from "+table+s_mmyy.Substring(2)+" where id="+l_id);
					a.delrec(dtct,"id="+l_id);
					ref_text(0);
				}
			}
			catch{}
		}

		private void tongcong()
		{
			try
			{
				decimal st=((dgiao.Text!="")?decimal.Parse(dgiao.Text):0)+((ntruoc.Text!="")?decimal.Parse(ntruoc.Text):0)+((bsung.Text!="")?decimal.Parse(bsung.Text):0);
				cong.Text=st.ToString(format_sotien);
			}
			catch{}
		}


		private void butIn_Click(object sender, System.EventArgs e)
		{	
		}


		private void find_TextChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==find) RefreshChildren(find.Text);
		}

		private void RefreshChildren(string text)
		{
			try
			{
				CurrencyManager cm= (CurrencyManager)BindingContext[dataGrid1.DataSource];
				DataView dv=(DataView)cm.List;			
				sql="sotk like '%"+text.Trim()+"%'";
				dv.RowFilter=sql;
			}
			catch(Exception ex){MessageBox.Show(ex.Message);}
		}

		private void find_Enter(object sender, System.EventArgs e)
		{
			find.Text="";
		}

		private void butFind_Click(object sender, System.EventArgs e)
		{
			/*frmTimthuoc f=new frmTimthuoc(d,s_mmyy,s_loai,i_nhom,i_userid,bAdmin);
			f.ShowDialog();*/
		}

		private void hoatdong_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode==Keys.Enter) SendKeys.Send("{Tab}");		
		}


		private void tkno_TextChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==tkno)
			{
				Filter_stk(tkno.Text,listtkno);
				listtkno.BrowseToDmtk(tkno,ttkno,nhmuc,tkno.Location.X,tkno.Location.Y+tkno.Height,tkno.Width+ttkno.Width+2,tkno.Height,100);
				//if (mtmno.Enabled)
				//	listtkno.BrowseToDmtk(tkno,ttkno,mtmno,tkno.Location.X,tkno.Location.Y+tkno.Height,tkno.Width+ttkno.Width+2,tkno.Height,100);
				//else if (kmno.Enabled)
				//	listtkno.BrowseToDmtk(tkno,ttkno,kmno,tkno.Location.X,tkno.Location.Y+tkno.Height,tkno.Width+ttkno.Width+2,tkno.Height,100);
				//else 
				//	listtkno.BrowseToDmtk(tkno,ttkno,dgiao,tkno.Location.X,tkno.Location.Y+tkno.Height,tkno.Width+ttkno.Width+2,tkno.Height,100);
			}
		}

		private void Filter_stk(string ma,LibList.List list)
		{
			try
			{
				CurrencyManager cm= (CurrencyManager)BindingContext[list.DataSource];
				DataView dv=(DataView)cm.List;
				sql="stk like '"+ma.Trim()+"%' or ttk like '%"+ma.Trim()+"%'";
				dv.RowFilter=sql;
			}
			catch{}
		}

		private void tkno_Validated(object sender, System.EventArgs e)
		{
			DataRow r=a.getrowbyid(dttk,"stk='"+tkno.Text+"'");
			ttkno.Text=(r!=null)?r["ttk"].ToString():"";	
			load_mtm(tkno.Text,mtmno,kmno);
		}

		private void load_mtm(string stk,TextBox txt,ComboBox cb)
		{
			cb.Enabled=txt.Enabled=false;
			DataTable tmp;
			DataRow r=a.getrowbyid(dttk,"stk='"+stk+"'");
			if (r!=null)
			{
				if (int.Parse(r["mlns"].ToString())==1 || int.Parse(r["ctmlns"].ToString())==1)
				{
					//nhmuc.Enabled=int.Parse(r["mlns"].ToString())==1 && butLuu.Enabled;
					if (butLuu.Enabled)//(nhmuc.Enabled==false)
					{					
						sql="select a.stk,a.ttk,a.id,b.tennhom ";
						sql+="from a_dmch a left join a_dmnhom b on a.nhmuc=b.id ";
						if (int.Parse(r["ctmlns"].ToString())==1) sql+=" where a.cd in (1,2) and a.sudung=1";//a.c=1
						else sql+=" where a.cd=2 and a.sudung=1";//a.sp=4
						sql+=" order by a.cc";
						tmp=a.get_data(sql).Tables[0];
						listmtm.DataSource=tmp;
						/*if (butLuu.Enabled) 
						{
							listmtm.Enabled=txt.Enabled=tmp.Rows.Count>0;
							if (txt.Enabled)
							{
								listtkno.Hide();
								txt.Focus();
							}
						}*/
					}
					else if (butLuu.Enabled) nhmuc.Focus();
				}
				sql="select * from a_dmkhoanmuc where loaikm="+int.Parse(r["loaikm"].ToString())+" and sudung=1 order by stt";
				tmp=a.get_data(sql).Tables[0];
				cb.DataSource=tmp;
				if (cb.Name=="kmno")
				{
					sql="select * from a_dmkhoanmuc where loaikm="+int.Parse(r["loaikm2"].ToString())+" and sudung=1 order by stt";
					kmno2.DataSource=a.get_data(sql).Tables[0];
					sql="select * from a_dmkhoanmuc where loaikm="+int.Parse(r["loaikm3"].ToString())+" and sudung=1 order by stt";
					kmno3.DataSource=a.get_data(sql).Tables[0];
					sql="select * from a_dmkhoanmuc where loaikm="+int.Parse(r["loaikm4"].ToString())+" and sudung=1 order by stt";
					kmno4.DataSource=a.get_data(sql).Tables[0];
				}
				if (butLuu.Enabled)
				{
					cb.Enabled=tmp.Rows.Count>0;
					if (cb.Name=="kmno") 
					{
						kmno2.Enabled=kmno2.Items.Count>0;
						kmno3.Enabled=kmno2.Items.Count>0;
						kmno4.Enabled=kmno4.Items.Count>0;
					}
					if (cb.Enabled)
					{
						listtkno.Hide();
						cb.Focus();
					}
				}
			}			
		}

		private void mtmno_TextChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==mtmno)
			{
				Filter_mtm(mtmno.Text);
				if (kmno.Enabled)
					listmtm.BrowseToDmtk(mtmno,stemp,kmno,mtmno.Location.X,mtmno.Location.Y+mtmno.Height,mtmno.Width,mtmno.Height,30);
				else 
					listmtm.BrowseToDmtk(mtmno,stemp,dgiao,mtmno.Location.X,mtmno.Location.Y+mtmno.Height,mtmno.Width,mtmno.Height,30);
			}		
		}

		private void mtmno_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listmtm.Focus();
			else if (e.KeyCode==Keys.Enter)
			{
				if (listmtm.Visible)	listmtm.Focus();
				else SendKeys.Send("{Tab}");
			}
		}
		private void Filter_mtm(string ma)
		{
			try
			{
				CurrencyManager cm= (CurrencyManager)BindingContext[listmtm.DataSource];
				DataView dv=(DataView)cm.List;
				sql="stk like '"+ma.Trim()+"%' or ttk like '%"+ma.Trim()+"%'";
				dv.RowFilter=sql;
			}
			catch{}
		}

		private void listtkno_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
			{
				try
				{
					tkno_Validated(sender,e);
					listtkno.Hide();
				}
				catch{}		
			}		
		}

		private void tkno_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listtkno.Focus();
			else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
			{
				if (listtkno.Visible)	listtkno.Focus();
				else nhmuc.Focus();
			}		
		}


		private void dgiao_Validated(object sender, System.EventArgs e)
		{
			try
			{
				decimal st=(dgiao.Text!="")?decimal.Parse(dgiao.Text):0;
				dgiao.Text=st.ToString(format_sotien);
			}
			catch{}
			tongcong();
		}

		private void ntruoc_Validated(object sender, System.EventArgs e)
		{
			try
			{
				decimal st=(ntruoc.Text!="")?decimal.Parse(ntruoc.Text):0;
				ntruoc.Text=st.ToString(format_sotien);
			}
			catch{}
			tongcong();
		}

		private void bsung_Validated(object sender, System.EventArgs e)
		{
			try
			{
				decimal st=(bsung.Text!="")?decimal.Parse(bsung.Text):0;
				bsung.Text=st.ToString(format_sotien);
			}
			catch{}
			tongcong();
		}

		private void hoatdong_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==hoatdong) load_loaikp();	
		}

		private void load_loaikp()
		{
			string sql="select * from a_dmng ";
			if (hoatdong.SelectedIndex!=-1) sql+=" where loaikp="+long.Parse(hoatdong.SelectedValue.ToString());
			sql+=" order by stt";
			loaikp.DataSource=a.get_data(sql).Tables[0];
		}

		private void nhmuc_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
			{
				mtmno.Enabled=nhmuc.SelectedIndex==-1;
				if (mtmno.Enabled) mtmno.Focus();
				else SendKeys.Send("{Tab}");
		}
		}
	}
}